#include <bits/stdc++.h>
using namespace std;
int T, n;
int a[200005];

int main()
{
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	
	cin >> T;
	while (T--){
		cin >> n;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		bool vis[200005];
		memset(vis, false, sizeof(vis));
		int ans = 0;
		for (int i = 2; i <= n; i++){
			int sum = 0;
			for (int j = i - 1; j >= 1; j--){
				if (a[i] == a[j]){
					ans += a[i];
					vis[i] = vis[j] = true;
					break;
				}
				if (vis[j])
					sum++;
				if (sum == 2)
					break;
			}
		}
		cout << ans << endl;
	}
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}
